<?php
/**
 * Created by PhpStorm.
 * User: hhcycj
 * Date: 2018\9\25 0025
 * Time: 15:53
 */


$pid = pcntl_fork();


echo "test" . PHP_EOL;

switch ($pid){
    case -1:
        die('Create failed');
        break;
    case 0:
        // Child
        echo "Child process id = " . posix_getpid() . PHP_EOL;

        sleep(2);

        echo "Child will exit" . PHP_EOL;

        break;
    default:
        // Parent

        $exit_id = pcntl_waitpid($pid, $status, WUNTRACED);

        if ($exit_id){
            echo "Child({$exit_id}) exited" . PHP_EOL;
        }

        echo "Master process id = " . posix_getpid() . PHP_EOL;
        break;
}

sleep(10);
